package LeetcodeTest_ten;
//加一
public class plusOne
{
    public static void main(String[] args)
    {
        int num[]={9,9,9,9};
        int answer[]=Solution.plusOne(num);
        for(int i=0;i<answer.length;i++)
            System.out.print(answer[i]+"  ");
    }
}
class Solution
{
    public static int[] plusOne(int[] digits)
    {
        int n=digits.length-1;
        while(n>=0)
        {
            if(digits[n]<9)
            {
                digits[n]++;
                break;
            }
            else
            {
                digits[n]=0;
                n=n-1;
            }
        }
        if(n==-1)
        {
            digits=new int[digits.length+1];
            digits[0]=1;
        }
        return digits;
    }
}
